<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //对象的解构赋值
      //1) 基本解构

      // let res= { name: '小王', age: 4 };
      // let name=res.name;
      // let age=res.age;

      let { age, name } = { name: '小王', age: 4 }
      console.log(name, age)
      //2) 可嵌套解构
      // let {
      //   p: [x, { y }]
      // } = { p: ['hello', { y: 'world' }] }
      // console.log(x, y)
      //3)不完全解构
      let {
        p: [{ y }, x]
      } = { p: [{ y: 'world' }] }
      console.log(x, y)
      //4)剩余运算符
      let { a, b, ...rest } = { a: 10, b: 20, c: 30, d: 40 }
      console.log(a, b, rest)

      //5) ...rest 剩余运算符函数用法
      function say(a, b, ...obj) {
        console.log(a, b, obj)
        console.log(arguments)
      }
      say('名字', 88, [1, 2, 3], '哈哈')
    </script>
  </body>
</html>
